package com.uqbar.asteroids.imageComponents;

import com.uqbar.asteroids.scenes.AsteroidScene;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Sprite;

public class ShipRender extends GameComponent<AsteroidScene> {

	private Sprite image;
	
	public Sprite getImage() {
		return image;
	}

	public void setImage(Sprite image) {
		this.image = image;
	}

	public ShipRender(Sprite sprite, double x, double y){
		this.image = sprite;
		this.setAppearance(this.image);
		this.setX(x);
		this.setY(y);
	}
	
	public void rotar(double radian){		
		this.setImage(this.obtenerImagenEnAngulo(radian));
		this.setAppearance(this.getImage());
	}
	
	private Sprite obtenerImagenEnAngulo(double radian) {
		Sprite img = this.getScene().getSpritesShip().get(0);
		for(int i = 0; i<this.getScene().getSpritesShip().size()-1;i++){
			img = this.getScene().getSpritesShip().get(i);		
				if(img.getRadian()>= radian){
					i = this.getScene().getSpritesShip().size() -1;
				}
		}
		return img;
	}
}
